package com.stud.framework.config.properties;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import org.redisson.codec.JsonCodec;
import org.redisson.codec.SerializationCodec;

import java.io.IOException;

/**
 * @author Stud
 * @title XXXXX
 * @desription XXXXX
 * @data 2022-11-10 15:57
 */
//public class FastJsonCodec<T> extends BaseCodec implements JsonCodec<T> {
//    private final Encoder encoder = in -> {
//        ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
//        try {
//            ByteBufOutputStream os = new ByteBufOutputStream(out);
//            JSON.writeTo(os, in, JSONWriter.Feature.WriteClassName);
//            return os.buffer();
//        } catch (Exception e) {
//            out.release();
//            throw new IOException(e);
//        }
//    };
//    private final Decoder<Object> decoder = (buf, state) -> JSON.parseObject(new ByteBufInputStream(buf), Object.class);
//
//    @Override
//    public Decoder<Object> getValueDecoder() {
//        return decoder;
//    }
//
//    @Override
//    public Encoder getValueEncoder() {
//        return encoder;
//    }
//}

public class FastJsonCodec<T> extends SerializationCodec implements JsonCodec<T> {

}
